package com.customer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.customer.dao.MemberLevelMapper;
import com.customer.service.MemberLevelService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nameless.entity.MemberLevel;
import com.nameless.vo.MemberLevelVo;
import com.nameless.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WHZ
 * @date 2023年02月28日 9:55
 */
@Service
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper, MemberLevel> implements MemberLevelService {

    @Autowired
    private MemberLevelMapper memberLevelMapper;

    @Autowired
    private MemberLevelService memberLevelService;

    @Override
    public Result findAll(Integer currentPage, Integer pageSize, MemberLevelVo memberLevelVo) {
        PageHelper.startPage(currentPage,pageSize);
        QueryWrapper<MemberLevel> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(memberLevelVo.getName()!=null,"name",memberLevelVo.getName());
        List<MemberLevel> memberLevels = memberLevelMapper.selectList(queryWrapper);
        PageInfo<MemberLevel> memberLevelPageInfo = new PageInfo<>(memberLevels);
        return new Result(200,"查询成功",memberLevelPageInfo);

    }

    @Override
    public Result add(MemberLevel memberLevel) {
        int insert = memberLevelMapper.insert(memberLevel);
        return new Result(200,"添加成功",insert);
    }

    @Override
    public Result del(Integer id) {
        int i = memberLevelMapper.deleteById(id);
        return new Result(200,"删除成功",i);
    }

    @Override
    public Result put(MemberLevel memberLevel) {
        int i = memberLevelMapper.updateById(memberLevel);
        return new Result(200,"修改成功",i);
    }

    @Override
    public MemberLevel selectMemberLevel(Integer id) {
        System.out.println(id);
        return memberLevelMapper.selectById(id);
    }
}
